package com.aat.dxfy.utils;

import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.aat.dxfy.utils.Atools;

public class JdbcEncodeSpringProps extends PropertyPlaceholderConfigurer {

	protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
			throws BeansException {
		Set<Entry<Object, Object>> entrys = props.entrySet();
		for (Entry<Object, Object> e : entrys) {
			String key = (String) e.getKey();
			String value = (String) e.getValue();
			if (key.contains("username") || key.contains("password")) {
				try {
					String s1= Atools.jiemi(value);
					props.setProperty(key, Atools.jiemi(s1));
				} catch (Exception e1) {
				}
			}
			if (key.contains("url")) {
				try {
					String ippt=Atools.jiemi(value);
					String val ="jdbc:mysql://"+ippt+"?useUnicode=true&characterEncoding=UTF8";
					props.setProperty(key, val);
				} catch (Exception e1) {
				}
			}
		}
		super.processProperties(beanFactory, props);// 调用父方法
	}
	
	

}